/**
 * Created with IntelliJ IDEA
 * Description:
 * User: SEKI TOMOKI
 * Date: 2023-09-11
 * Time: 21:46
 */
class Solution {
    public boolean isAlphanumericCharacters(char ch) {
        if( (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') ) {
            return true;
        }else {
            return false;
        }
    }

    public boolean isPalindrome(String s) {
        String lowerStr =  s.toLowerCase();
        int i = 0;
        int j = s.length() - 1;

        while(i < j) {
            while((i < j) && !isAlphanumericCharacters(lowerStr.charAt(i)) ) {
                i++;
            }

            while((i < j) && !isAlphanumericCharacters(lowerStr.charAt(j)) ) {
                j--;
            }

            if(lowerStr.charAt(i) == lowerStr.charAt(j)) {
                i++;
                j--;
            }else {
                return false;
            }

        }
        return true;
    }
}